# conftest.py

import pytest
from utils.common_actions import take_screenshot


# @pytest.hookimpl(hookwrapper=True)
# def pytest_runtest_makereport(item, call):
#     outcome = yield
#     if call.when == "call":
#         try:
#             outcome.excinfo and take_screenshot(item.funcargs["d"], "fail")
#         except Exception as e:
#             print("截图失败:", e)

# conftest.py

import os
import pytest
from utils.common_actions import take_screenshot

SCREENSHOT_DIR = "results/screenshots"
os.makedirs(SCREENSHOT_DIR, exist_ok=True)

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    if call.when in ["setup", "call"]:
        if outcome.excinfo:
            test_name = item.name
            case_dir = os.path.join(SCREENSHOT_DIR, test_name)
            os.makedirs(case_dir, exist_ok=True)
            d = item.funcargs.get("d")
            if d:
                take_screenshot(d, name=os.path.join(test_name, f"error_{call.when}"))
    return outcome




